set(src_modules
    additional_kpoints.f90 
    atomic_wfc_mod.f90
    autopilot.f90 
    ions_nose.f90
    cell_nose.f90
    basic_algebra_routines.f90 
    becmod.f90 
    bfgs_module.f90 
    bspline.f90 
    bz_form.f90 
    cell_base.f90  
    check_stop.f90  
    command_line_options.f90 
    compute_dipole.f90 
    constants.f90 
    constraints_module.f90 
    control_flags.f90 
    coulomb_vcut.f90  
    dist.f90 
    electrons_base.f90 
    environ_base_module.f90
    environment.f90 
    extffield.f90
    fd_gradient.f90 
    fft_base.f90 
    fft_rho.f90 
    fft_wave.f90 
    fsockets.f90 
    funct.f90 
    generate_function.f90 
    gradutils.f90 
    gvecw.f90 
    input_parameters.f90 
    invmat.f90 
    io_files.f90 
    io_global.f90  
    ions_base.f90 
    kind.f90 
    lmdif.f90
    makov_payne.f90
    mdiis.f90 
    mm_dispersion.f90 
    mp_bands.f90 
    mp_exx.f90 
    mp_global.f90 
    mp_images.f90 
    mp_pools.f90 
    mp_wave.f90 
    mp_world.f90 
    noncol.f90 
    open_close_input_file.f90 
    parameters.f90 
    parser.f90 
    plugin_flags.f90 
    plugin_arguments.f90 
    plugin_variables.f90 
    printout_base.f90
    pw_dot.f90 
    qmmm.f90 
    random_numbers.f90 
    read_cards.f90 
    read_input.f90 
    read_namelists.f90 
    read_pseudo.f90 
    recvec.f90 
    recvec_subs.f90 
    run_info.f90 
    space_group.f90 
    set_para_diag.f90 
    set_signal.f90 
    set_vdw_corr.f90 
    copy_order_um_from_xml.f90
    setqf.f90 
    timestep.f90
    tsvdw.f90
    mbdlib.f90
    version.f90 
    wannier_gw.f90
    wannier_new.f90 
    wavefunctions.f90 
    ws_base.f90 
    xc_vdW_DF.f90 
    xc_rVV10.f90 
    io_base.f90 
    qes_types_module.f90 
    qes_libs_module.f90  
    qes_write_module.f90 
    qes_read_module.f90 
    qes_reset_module.f90 
    qes_init_module.f90 
    qes_bcast_module.f90 
    qexsd.f90   
    qexsd_copy.f90   
    qexsd_init.f90   
    qexsd_input.f90 
    hdf5_qe.f90
    qeh5_module.f90
    fox_init_module.f90 
    xsf.f90 
    wyckoff.f90 
    wypos.f90 
    zvscal.f90 
    wave_gauge.f90
    # list of RISM's modules
    allocate_fft_3drism.f90
    chempot.f90
    chempot_lauerism.f90
    closure.f90
    corrdipole_laue.f90
    correctat0_vv.f90
    corrgxy0_laue.f90
    cryst_to_car_2d.f90
    data_structure_3drism.f90
    do_1drism.f90
    do_3drism.f90
    do_lauerism.f90
    eqn_1drism.f90
    eqn_3drism.f90
    eqn_lauedipole.f90
    eqn_lauegxy0.f90
    eqn_lauelong.f90
    eqn_lauerism.f90
    eqn_laueshort.f90
    eqn_lauevoid.f90
    err_rism.f90
    guess_3drism.f90
    init_1drism.f90
    init_3drism.f90
    input_1drism.f90
    input_3drism.f90
    io_rism_xml.f90
    lauefft.f90
    lauefft_subs.f90
    lj_forcefield.f90
    lj_solute.f90
    molecorr_vv.f90
    molebridge_vv.f90
    molecule_const.f90
    molecule_types.f90
    mp_rism.f90
    mp_swap_ax_rism.f90
    normalize_lauerism.f90
    plot_rism.f90
    potential_3drism.f90
    potential_esm.f90
    potential_vv.f90
    print_chempot_3drism.f90
    print_chempot_lauerism.f90
    print_chempot_vv.f90
    print_corr_vv.f90
    print_solvavg.f90
    radfft.f90
    read_mol.f90
    read_solv.f90
    recvec_3drism.f90
    rism.f90
    rism1d_facade.f90
    rism3d_facade.f90
    rms_residual.f90
    scale_fft_3drism.f90
    scale_fft_lauerism.f90
    solute.f90
    solvation_3drism.f90
    solvation_esm.f90
    solvation_force.f90
    solvation_lauerism.f90
    solvation_pbc.f90
    solvation_stress.f90
    solvavg.f90
    solvmol.f90
    summary_1drism.f90
    summary_3drism.f90
    suscept_g0.f90
    suscept_laue.f90
    suscept_laueint.f90
    suscept_vv.f90
    write_rism_type.f90
    xml_io_rism.f90
    # subroutines and functions (not modules) previously found in flib
    atom_weight.f90 
    capital.f90 
    cryst_to_car.f90
    expint.f90 
    generate_k_along_lines.f90 
    more_functionals.f90 
    has_xml.f90 
    inpfile.f90 
    int_to_char.f90 
    latgen.f90 
    linpack.f90 
    matches.f90 
    plot_io.f90 
    radial_gradients.f90 
    rgen.f90 
    recips.f90 
    remove_tot_torque.f90
    sort.f90 
    trimcheck.f90 
    test_input_file.f90 
    date_and_tim.f90 
    volume.f90 
    wgauss.f90 
    w0gauss.f90
    w1gauss.f90
    deviatoric.f90
    # GPU
    random_numbers_gpu.f90)
qe_enable_cuda_fortran("${src_modules}")
qe_add_library(qe_modules ${src_modules})

# subroutines and functions (not modules) previously found in clib
set(src_modules_c
    customize_signals.c
    qmmm_aux.c
    sockets.c)
add_library(qe_modules_c ${src_modules_c})

if(TARGET gitrev)
   add_dependencies(qe_modules gitrev)
   target_compile_definitions(qe_modules PRIVATE HAVE_GITREV)
   target_include_directories(qe_modules PRIVATE ${qe_BINARY_DIR})
endif()

target_link_libraries(qe_modules
    PRIVATE
        qe_device_lapack  
        qe_modules_c
        qe_openmp_fortran
        qe_fftx
        qe_lax
        qe_mpi_fortran
        qe_mbd
        qe_xclib
        qe_devxlib
    PUBLIC
        qe_openacc_fortran
        qe_hdf5_fortran
        qe_upflib
        qe_fox
        qe_utilx
        qe_openacc_fortran)
if(QE_ENABLE_CUDA)
    target_link_libraries(qe_modules
        PRIVATE
            CUDA::curand)
endif()

if(QE_ENABLE_ENVIRON)
    target_link_libraries(qe_modules
    PUBLIC
        qe_environ)
endif()

###########################################################

qe_install_targets(qe_modules qe_modules_c)
